home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-15 | 4.8 KB | 130 lines | [TEXT/KAHL] |
- In article <jhiggins-101293131825@144.212.1.91>, jhiggins@mathworks.com (John
- M. Higgins) wrote:
- >
- > Is there any way to convince PBCatSearch to start its search in a
- > subdirectory? The parameter block that this function requires has a
- > CatPosition record which is set to 0 to start searching at the root level.
- > Inside Mac doesn’t give any clue as to what this value means. Directory
- > IDs do not seem to work. Perhaps the search does not descend through the
- > file hierarchy in an orderly fashion, or perhaps not. Anyone know?
- >
-
- OK. I finally decided to show the world that Taligent programmers indeed do
- know how to program, and I wrote something to address this need.
-
- PBCatSearch doesn’t have any way to allow the programmer to specify a folder
- hierarchy to search within. It will let you specify a specific folder to look
- in, but not the sub-folders within that folder. The reason for this is that
- PBCatSearch searches the catalog file linearly, the format of which bears no
- resemblance to the folder hierarchy.
-
- I’ve always felt that there are two approaches to coming up with a PBCatSearch
- that does what people are asking for:
-
- 1) Search the entire hard disk for files with the characteristics you are
- interested in. For each file found, walk up the directory chain to see if the
- file is within the folder you’re interested in. To speed things up, cache the
- results of the chain walking so that you don’t have to perform them again if
- you find multiple files in the same sub-folder.
-
- 2) Pre-flight the search by walking the directory structure you’re interested
- in. During the walk, record the dirID of each directory you find. Then do the
- full disk search. For each file you find, compare its dirID with the list you
- made.
-
- I implemented both this weekend to see how well they worked. I first tried #1,
- thinking that, with appropriate caching, it would be faster. Not getting the
- performance I wanted, I then tried #2. This one turned out to be slightly
- faster for the test case I was using, and the code was much smaller. Here are
- some comparisons:
-
- Look for all MPW tools...
- o ... on my 400 Meg internal drive: 7 seconds
- o ... within my MPW folder, using approach #1: 12 seconds
- o ... within my MPW folder, using approach #2: 10 seconds
-
- The interface to this routine is:
-
- OSErr PBCatSearchIn(CSParamBlockRec*, long dirID);
-
- By the way, I also took this opportunity to write something I’d always wanted
- to do: a high-level interface to PBCatSearch. This CatSearch routine uses a
- varargs interface, and works surprisingly well! For instance, to find my MPW
- Shell file, I say:
-
- err = CatSearch(&numberFound,
- csVRefNum, (short) -2,
- csMatchPtr, &MPWSpec, (long) 1,
- csFullName, "\pMPW Shell",
- csFInfoFDType, 'APPL', // or else it will find my alias!
- csEndList);
-
- (I apologize to everyone for hard-coding my vRefNum in the call!)
-
- This says: search for “MPW Shell”, which is an application on the specified
- volume. Find the first instance of it, and return the FSSpec in MPWSpec.
-
- Now let’s say that you wanted to find all MPW tools on your volume. This could
- be done as follows:
-
- err = CatSearch(&numberFound,
- csVRefNum, (short) -2,
- csMatchPtr, pMatchBuffer, (long) kMaxMatches,
- csFInfoFDType, 'MPST',
- csFInfoFDCreator, 'MPS ',
- csEndList);
- while ((err == noErr) || (err == eofErr))
- {
- for (loopy = 0; loopy < numberFound; ++loopy)
- {
- ...process files....
- }
-
- if (err == noErr)
- err = CatSearch(&numberFound, csContinue);
- else
- break;
- }
-
- Note the use of the “csContinue” feature. CatSearch remembers the last set of
- values passed to it and will reuse them if you want. Even so, I’ve found the
- loop structure used here a little awkward, so I also implemented a
- “csInitOnly” option. This option will let you specify the search options, but
- not actually perform the search. You can then write a loop like the
- following:
-
- err = CatSearch(&numberFound,
- csVRefNum, (short) -2,
- csMatchPtr, pMatchBuffer, (long) kMaxMatches,
- csFInfoFDType, 'MPST',
- csFInfoFDCreator, 'MPS ',
- csInitOnly, // <<<<<<<<------ this was added
- csEndList);
-
- while (err == noErr)
- {
- err = CatSearch(&numberFound, csContinue);
- if ((err == noErr) || (err == eofErr))
- {
- for (loopy = 0; loopy < numberFound; ++loopy)
- {
- ...process files....
- }
- }
- }
-
- CatSearch also supports PBCatSearchIn, so you can specify a sub-directory
- search thusly:
-
- err = CatSearch(&numberFound,
- csVRefNum, MPWSpec.vRefNum,
- csMatchPtr, pMatchBuffer, (long) kMaxMatches,
- csFInfoFDType, 'MPST',
- csFInfoFDCreator, 'MPS ',
- csSearchInDirectory, MPWSpec.parID, // <<<<<<<<------ this was added
- csInitOnly,
- csEndList);
-
- --------------------------------------------------------------------------
- Keith Rollin --- Phantom Programmer --- Taligent, Inc.
-